#include <QCoreApplication>
#include "iostream"

using namespace std;


uint32_t uint32_hex(string str){
    return strtoul(str.c_str(), nullptr, 16);
}

int32_t getBlockHeightFromCoinbase(const string &coinbase1){
    // https://github.com/bitcoin/bips/blob/master/bip-0034.mediawiki
    const string a = coinbase1.substr(86, 2);
    const string b = coinbase1.substr(88, 2);
    const string c = coinbase1.substr(90, 2);
    const string heightHex = c + b + a;  // little-endian

    return (int32_t)strtol(heightHex.c_str(), nullptr, 16);
}

string hello_world(){
    const string s = "Hello world!";
    return s;
}

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    cout << hello_world() << endl;

    cout << getBlockHeightFromCoinbase("01000000010000000000000000000000000000000000000000000000000000000000000000ffffffff64038b1d082cfabe6d6d70ec09c83907cb984ce5384d84bba9750b5523eae061e7cfcb426ccfbeee994b08000000f09f909f00104d696e656420627920676f6c6478696e0000000000000000000000000000000000000000000000000000000000000000") << endl;

    cout << uint32_hex("17347a28") << endl;

    time_t currTime = time(nullptr);
    cout << currTime << endl;  // 1531729307
    cout << (uint32_t)currTime << endl;  // 1531729307

    return a.exec();
}
